package com.moyun.finance.utils;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 日期处理
 */
public class DateUtils {
    /**
     * 验证字符串时间，下个月之前
     * @param str
     * @return
     */
    public static boolean isValidDate(String str) throws ParseException {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.add(Calendar.DAY_OF_MONTH, 30);
        Date sDate = cal.getTime();
        if(new SimpleDateFormat("yyyy-MM-dd").parse(str).getTime() < sDate.getTime()){
            return true;
        }
        return false;
    }

    public static String formatDate(String str) throws ParseException{
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.parse(str).toString();
    }

    public static String formatDate(Date date){
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
    }
}
